<?php
/**
 * Created by PhpStorm.
 * User: yanghe
 * Date: 2016/5/10
 * Time: 16:44
 */
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use MyClass\Admin\ImageBase;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\DB;
class ImageController extends Controller
{
    public function sImage()
    {
        session(["nowPage"=>"/user_sImage"]);
        $data=ImageBase::sImage();
        //dump($data);die;
        return view("Admin.Image.sImage",$data);
    }

    public function dImage($image_id){
        $data=ImageBase::dImage($image_id);
        if($data){
            return redirect("/user_sImage");
        }else{
            return false;
        }
    }

    public function test(){
        return view("Admin.Image.testaImage");
    }
    public function _test(){
        $data = [];

        if (!request::hasFile('file')) {

            echo "没有文件";
            die;
        } else {
            //从前端提取文件

            $file = Request::file('file');
            //提取文件名
            $fileName = $file->getClientOriginalName();

            //移动文件到指定目录
            $storage_path = "/uploads/";  //存贮文件的绝对路径
            $path = $_SERVER['DOCUMENT_ROOT'] .$storage_path ;//C:/Wnmp/PHP_Project/shiyanshi/public/uploads/
            $name = date('YmdHis') . rand(1000, 9999) . "." . $file->getClientOriginalExtension();  //自动生成路径

            echo $path;
            echo "<br>";
            echo $name;

            $file->move($path, $name);  //移动

            //把文件相关数据插入数据库
            $input_data["image_name"] ="编辑器上传图片".$name;  //改文件名1
            $input_data["image_intro"] = "编辑器上传图片".$name;
            $input_data["image_path"] = $storage_path.$name;  //绝对路径
            $input_data['image_create_time']=date("y-m-d h:i:s",time());
            if ($id = DB::table("image")->insertGetId($input_data)){

                echo "数据库添加成功";

            } else {
                echo "存入数据库失败";
            }
        }
    }
}